﻿<UserControl x:Class="ExampleControl.Controls.MapSourceControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
    <Grid x:Name="LayoutRoot" >

        <Grid.Resources>
            <ItemsPanelTemplate x:Key="ItemsPanelTemplate">
                <StackPanel/>
            </ItemsPanelTemplate>
            <Style x:Key="BaseLayersListBox" TargetType="ListBox">
                <Setter Property="Margin" Value="1" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBox">
                            <Grid>
                                <ItemsPresenter />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="BaseLayerListBoxItem" TargetType="ListBoxItem">
                <Setter Property="Foreground" Value="#FFFFFFFF" />
                <Setter Property="Margin" Value="8,0,4,0" />
                <Setter Property="Height" Value="15" />
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="VerticalAlignment" Value="Bottom" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBoxItem">
                            <Grid Cursor="Arrow">
                                <Grid.Resources>
                                    <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF" />
                                    <LinearGradientBrush x:Key="BoxStrokeBrush" StartPoint="0.5,0" EndPoint="0.5,1">
                                        <GradientStop Color="#FF000000" Offset="0" />
                                        <GradientStop Color="#FF000000" Offset="1" />
                                        <GradientStop Color="#FF000000" Offset="0.325" />
                                        <GradientStop Color="#FF000000" Offset="0.325" />
                                    </LinearGradientBrush>
                                    <LinearGradientBrush x:Key="FocusedStrokeBrush" StartPoint="0.5,0" EndPoint="0.5,1">
                                        <GradientStop Color="#B2FFFFFF" Offset="0" />
                                        <GradientStop Color="#51FFFFFF" Offset="1" />
                                        <GradientStop Color="#66FFFFFF" Offset="0.325" />
                                        <GradientStop Color="#1EFFFFFF" Offset="0.325" />
                                    </LinearGradientBrush>
                                    <Color x:Key="BorderColor">#FF000000</Color>
                                    <Color x:Key="IconColor">#FF313131</Color>
                                    <Color x:Key="PressedIconColor">#FFFFFFFF</Color>
                                    <Color x:Key="IconColorBack">#FFFFFFFF</Color>
                                    <Color x:Key="MiddleBoxStrokeBrush">#FFADADAD</Color>
                                    <Color x:Key="MiddleBoxStrokeBrushOver">#FF656565</Color>
                                    <Color x:Key="LinearBevelLightStartColor">#FFFFFFFF</Color>
                                    <Color x:Key="LinearBevelLightEndColor">#FFFFFFFF</Color>
                                    <Color x:Key="LinearBevelDarkStartColor">#FFFFFFFF</Color>
                                    <Color x:Key="LinearBevelDarkEndColor">#FFFFFFFF</Color>
                                    <Color x:Key="LinearBevelLightStartColor2">#FCFFFFFF</Color>
                                    <Color x:Key="LinearBevelLightEndColor2">#e4FFFFFF</Color>
                                    <Color x:Key="LinearBevelDarkStartColor2">#E0FFFFFF</Color>
                                    <Color x:Key="LinearBevelDarkEndColor2">#19FFFFFF</Color>
                                    <Color x:Key="LinearBevelLightEndColor3">#FCFFFFFF</Color>
                                    <Color x:Key="LinearBevelDarkStartColor3">#FCFFFFFF</Color>
                                    <Color x:Key="LinearBevelDarkEndColor3">#FCFFFFFF</Color>
                                    <Color x:Key="LinearBevelIndeterminateStartColor2">#A0FFFFFF</Color>
                                    <Color x:Key="LinearBevelIndeterminateEndColor2">#19FFFFFF</Color>
                                    <Color x:Key="FocusColor">#FF333333</Color>
                                </Grid.Resources>
                                <vsm:VisualStateManager.VisualStateGroups>
                                    <vsm:VisualStateGroup x:Name="CommonStates">
                                        <vsm:VisualStateGroup.Transitions>
                                            <vsm:VisualTransition To="MouseOver" GeneratedDuration="0:0:0.1" />
                                            <vsm:VisualTransition To="Pressed" GeneratedDuration="0:0:0.1" />
                                        </vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualState x:Name="Normal" />
                                        <vsm:VisualState x:Name="MouseOver">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="Box" Storyboard.TargetProperty="Opacity" To=".65" Duration="0" />
                                                <ColorAnimation Storyboard.TargetName="BoxMiddleStroke" Storyboard.TargetProperty="Color" To="{StaticResource MiddleBoxStrokeBrushOver}" Duration="0" />
                                            </Storyboard>
                                        </vsm:VisualState>
                                        <vsm:VisualState x:Name="Pressed">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="Box" Storyboard.TargetProperty="Opacity" To=".35" Duration="0" />
                                                <ColorAnimation Storyboard.TargetName="BoxMiddleStroke" Storyboard.TargetProperty="Color" To="{StaticResource MiddleBoxStrokeBrushOver}" Duration="0" />
                                            </Storyboard>
                                        </vsm:VisualState>
                                        <vsm:VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="DisabledBox" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                            </Storyboard>
                                        </vsm:VisualState>
                                    </vsm:VisualStateGroup>
                                    <vsm:VisualStateGroup x:Name="SelectionStates">
                                        <vsm:VisualState x:Name="Selected">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="CheckIcon" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                                <DoubleAnimation Storyboard.TargetName="CheckIconBack" Storyboard.TargetProperty="Opacity" To=".3" Duration="0" />
                                                <DoubleAnimation Storyboard.TargetName="BoxMiddleBackground" Storyboard.TargetProperty="Opacity" To=".75" Duration="0" />
                                            </Storyboard>
                                        </vsm:VisualState>
                                        <vsm:VisualState x:Name="Unselected" />
                                    </vsm:VisualStateGroup>

                                    <vsm:VisualStateGroup x:Name="FocusStates">
                                        <vsm:VisualState x:Name="Unfocused">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Collapsed</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </vsm:VisualState>
                                        <vsm:VisualState x:Name="Focused">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Collapsed</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </vsm:VisualState>
                                        <vsm:VisualState x:Name="ContentFocused">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentFocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <Visibility>Visible</Visibility>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </vsm:VisualState>
                                    </vsm:VisualStateGroup>
                                </vsm:VisualStateManager.VisualStateGroups>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Ellipse x:Name="BoxBackground" Width="13" Height="13" StrokeThickness="1" Stroke="{StaticResource BoxStrokeBrush}" Fill="{TemplateBinding Background}" VerticalAlignment="Center" />
                                <Ellipse x:Name="Box" Width="12" Height="12" StrokeThickness="0" VerticalAlignment="Center" Opacity="1">
                                    <Ellipse.Fill>
                                        <LinearGradientBrush StartPoint="0.7,0" EndPoint="0.7,1">
                                            <GradientStop x:Name="LinearBevelLightStart" Color="{StaticResource LinearBevelLightStartColor}" Offset="0" />
                                            <GradientStop x:Name="LinearBevelLightEnd" Color="{StaticResource LinearBevelLightEndColor}" Offset="0.35" />
                                            <GradientStop x:Name="LinearBevelDarkStart" Color="{StaticResource LinearBevelDarkStartColor}" Offset="0.35" />
                                            <GradientStop x:Name="LinearBevelDarkEnd" Color="{StaticResource LinearBevelDarkEndColor}" Offset="1" />
                                        </LinearGradientBrush>
                                    </Ellipse.Fill>
                                </Ellipse>
                                <Ellipse x:Name="BoxMiddleBackground" Width="9" Height="9" StrokeThickness=".5" Fill="{TemplateBinding Background}" VerticalAlignment="Center" Opacity=".20" />
                                <Ellipse x:Name="BoxMiddle" Width="9" Height="9" StrokeThickness=".5" VerticalAlignment="Center">
                                    <Ellipse.Stroke>
                                        <SolidColorBrush x:Name="BoxMiddleStroke"  Color="{StaticResource MiddleBoxStrokeBrush}" />
                                    </Ellipse.Stroke>
                                    <Ellipse.Fill>
                                        <LinearGradientBrush StartPoint="0.7,0" EndPoint="0.7,1">
                                            <GradientStop x:Name="LinearBevelLightStart2" Color="{StaticResource LinearBevelLightStartColor2}" Offset="0" />
                                            <GradientStop x:Name="LinearBevelLightEnd2" Color="{StaticResource LinearBevelLightEndColor2}" Offset="0.35" />
                                            <GradientStop x:Name="LinearBevelDarkStart2" Color="{StaticResource LinearBevelDarkStartColor2}" Offset="0.35" />
                                            <GradientStop x:Name="LinearBevelDarkEnd2" Color="{StaticResource LinearBevelDarkEndColor2}" Offset="1" />
                                        </LinearGradientBrush>
                                    </Ellipse.Fill>
                                </Ellipse>
                                <!-- Checked visual -->
                                <Ellipse x:Name="CheckIconBack" Width="9" Height="9" StrokeThickness=".5" VerticalAlignment="Center" Opacity="0">
                                    <Ellipse.Fill>
                                        <SolidColorBrush x:Name="IconColorBack"  Color="{StaticResource IconColorBack}" />
                                    </Ellipse.Fill>
                                </Ellipse>
                                <Ellipse x:Name="CheckIcon" Width="4" Height="4" Stretch="Fill" Opacity="0">
                                    <Ellipse.Fill>
                                        <SolidColorBrush x:Name="CheckIconColor"  Color="{StaticResource IconColor}" />
                                    </Ellipse.Fill>
                                </Ellipse>
                                <!-- Focus indicator -->
                                <Rectangle Grid.Column="1" x:Name="ContentFocusVisual" StrokeDashCap="Round" Margin="2" StrokeDashArray=".2 2" Visibility="Collapsed" IsHitTestVisible="false">
                                    <Rectangle.Stroke>
                                        <SolidColorBrush Color="{StaticResource FocusColor}" />
                                    </Rectangle.Stroke>
                                </Rectangle>

                                <ContentPresenter Grid.Column="1" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Margin}" IsHitTestVisible="true" />
                                <!-- Disabled -->
                                <Ellipse x:Name="DisabledBox" Width="13" Height="13" StrokeThickness=".75"  Stroke="{StaticResource DisabledBrush}"  Fill="{StaticResource DisabledBrush}"  VerticalAlignment="Center" Opacity="0" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>

        <ListBox 
                                x:Name="_Toolbar" 
                                Style="{StaticResource BaseLayersListBox}" 
                                ItemContainerStyle="{StaticResource BaseLayerListBoxItem}" 
                                ItemsPanel="{StaticResource ItemsPanelTemplate}"/>

    </Grid>
</UserControl>
